package com.kuang.service.impl;

import com.kuang.dao.LogsMapper;
import com.kuang.pojo.Logs;
import com.kuang.service.LogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogsServiceImpl implements LogsService {
    @Autowired
    private LogsMapper logsmapper;

    @Override
    public int insertUserIp(Logs userIp) {
        return logsmapper.insertUserIp(userIp);
    }

    @Override
    public List<Logs> selectUserIpPage(Integer pageindex, Integer pagesize) {
        return logsmapper.findPage(pageindex, pagesize);
    }

    @Override
    public int countUserIp() {
        return logsmapper.countLogs();
    }

    @Override
    public int deleteUserIp(Integer useripid) {
        return logsmapper.deleteById(useripid);
    }

    @Override
    public int insertLogs(Logs logs) {
        String operation = logs.getOperation();
        if (operation.contains("/toindex")) {
            logs.setOperation("访问首页");
        } else if (operation.contains("totype")) {
            logs.setOperation("访问分类页");
        } else if (operation.contains("totag")) {
            logs.setOperation("访问标签页");
        } else if (operation.contains("toarchive")) {
            logs.setOperation("访问归档页");
        }
        else if (operation.contains("toblogdetail")){
            logs.setOperation("访问博客详情");
        }else if (operation.contains("/")){
            logs.setOperation("访问首页");

        }
        return logsmapper.saveLogs(logs);
    }


}
